home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / utility / uwserver.zip / uwserver.tar / lib / uw_kill.c < prev    next >
C/C++ Source or Header  |  1991-01-25  |  1KB  |  55 lines

  1. /*
  2.  *    uw library - uw_kill
  3.  *
  4.  * Copyright 1986 by John D. Bruner.  All rights reserved.  Permission to
  5.  * copy this program is given provided that the copy is not sold and that
  6.  * this copyright notice is included.
  7.  */
  8. #include <sys/types.h>
  9. #include <netinet/in.h>
  10.  
  11. #include "uwlib.h"
  12.  
  13. #ifndef htons
  14. /* These should have been defined in <netinet/in.h>, but weren't (in 4.2BSD) */
  15. extern unsigned short htons(), ntohs();
  16. extern unsigned long htonl(), ntohl();
  17. #endif
  18.  
  19. uw_kill(uwin)
  20. UWIN uwin;
  21. {
  22.     register int len;
  23.     struct uwipc uwip;
  24.     extern int errno;
  25.  
  26.     /*
  27.      * Kill the window "uwin".  After putting out the contract,
  28.      * destroy the evidence by closing all existing connections
  29.      * to the window.
  30.      */
  31.     if (uwin != (UWIN)0) {
  32.         if (uwin->uwi_ctlfd >= 0) {
  33.             len = sizeof uwip.uwip_killw +
  34.                 (char *)&uwip.uwip_killw - (char *)&uwip;
  35.             uwip.uwip_len = htons(len);
  36.             uwip.uwip_cmd = htons(UWC_KILLW);
  37.             uwip.uwip_killw.uwkw_id = htonl(uwin->uwi_id);
  38.             if (write(uwin->uwi_ctlfd, (char *)&uwip, len) < 0) {
  39.                 uwin->uwi_errno = errno;
  40.                 uwerrno = uwin->uwi_uwerr = UWE_ERRNO;
  41.             } else
  42.                 uwerrno = uwin->uwi_uwerr = UWE_NONE;
  43.             (void)uw_detach(uwin);
  44.         } else
  45.             uwerrno = uwin->uwi_uwerr = UWE_NOCTL;
  46.         if (uwin->uwi_uwerr == UWE_NONE)
  47.             return(0);
  48.         else
  49.             return(-1);
  50.     } else {
  51.         uwerrno = UWE_INVAL;
  52.         return(-1);
  53.     }
  54. }
  55.